home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
ptf12.zip
/
PTFMAIN.SRC
< prev
next >
Wrap
Text File
|
1990-05-12
|
33KB
|
1,242 lines
--::::::::::
--ptf.a
--::::::::::
-- ..................................
-- . .
-- . PTF (Portable_Text_Formatter) . SPEC & BODY
-- . .
-- ..................................
with Command_Line_Processor;
with Command_Symbols;
with Console;
with Error_Log;
with Index;
with Output_File;
with Variable;
with Word_Processor;
procedure Ptf is
--| Purpose
--| Portable_Text_Formatter feeds the Word_Processor with files
--| to process.
--|
--| Exceptions (none)
--| Notes (none)
--| Modifications
--| 02/26/90 Rick Conn Add Disable Underline, Disable All
--| 02/26/90 Rick Conn Fix check for number of file name arguments
--| from 0-1 to 0-2 causing an error message
--| 02/26/90 Rick Conn Don't open output file if Cancel
--| 05/07/90 Rick Conn FILE_LISTER2 removed and CLP added
Signon
: constant STRING
:= "PTF, Version 1.2";
Error_Log_File_Name
: constant STRING
:= "ptf.err";
File_Name_Length
: constant
:= 100;
subtype FILE_NAME_STRING is
STRING (1 .. File_Name_Length);
File_Name
: FILE_NAME_STRING;
File_Name_Last
: NATURAL;
Valid_Options
: BOOLEAN
:= true;
Help_Displayed
: BOOLEAN
:= false;
Page_Offset
: NATURAL
:= 0;
Disable_Bolding_Flag
: BOOLEAN
:= false;
Disable_Underlining_Flag
: BOOLEAN
:= false;
Error_Logging_Flag
: BOOLEAN
:= false;
subtype OPTION_STRING is
STRING (1 .. 2);
type OPTION_ID is
( DISABLE_BOLDING, DISABLE_UNDERLINING, DISABLE_ALL,
DISPLAY_HELP, ERROR_LOGGING, SET_PAGE_OFFSET, UNKNOWN );
type OPTION_TYPE is
record
Name : OPTION_STRING;
Id : OPTION_ID;
end record;
type OPTION_LIST is
array (NATURAL range <>)
of OPTION_TYPE;
Option
: constant OPTION_LIST
:= (("da", DISABLE_ALL),
("DA", DISABLE_ALL),
("db", DISABLE_BOLDING),
("DB", DISABLE_BOLDING),
("du", DISABLE_UNDERLINING),
("DU", DISABLE_UNDERLINING),
("el", ERROR_LOGGING),
("EL", ERROR_LOGGING),
("h ", DISPLAY_HELP),
("H ", DISPLAY_HELP),
("PO", SET_PAGE_OFFSET),
("po", SET_PAGE_OFFSET));
use Command_Symbols;
use Word_Processor; -- visibility of "="
package CLP renames Command_Line_Processor;
-- ..................................
-- . .
-- . Help_Message . SPEC & BODY
-- . .
-- ..................................
procedure Help_Message is
--| Purpose
--| Help_Message displays a help message to the user at the console.
--|
--| Exceptions (none)
--| Notes (none)
begin -- Help_Message
Console.Put_Line("Syntax: ptf [-option]* infile1 [infileN]* outfile");
Console.Put_Line("Options:");
Console.Put_Line(" da Disable all backspacing features");
Console.Put_Line(" db Disable boldface feature");
Console.Put_Line(" du Disable underline feature");
Console.Put_Line(" el Log errors to ptf.err");
Console.Put_Line(" poN Offset pages by N columns");
Console.Put_Line(" h or H This message");
Help_Displayed := true;
end Help_Message;
-- ..................................
-- . .
-- . Is_File . SPEC & BODY
-- . .
-- ..................................
function Is_File
( Item : in STRING )
return BOOLEAN is
--| Purpose
--| Is_File returns TRUE if the Item does not begin with a dash.
--|
--| Exceptions (none)
--| Notes (none)
begin -- Is_File
return Item(Item'First) /= '-';
end Is_File;
-- ....................................
-- . .
-- . Process_Options . SPEC & BODY
-- . .
-- ....................................
procedure Process_Options
( Item : in STRING ) is
--| Purpose
--| This routine processes the option if Item begins with a dash.
--|
--| Exceptions (none)
--| Notes
--| Valid_Options may be modified if an option error occurred
--| Disable_Bolding_Flag and Disable_Underlining_Flag may be modified
--| if the DISABLE_ALL option is selected
--| Disable_Bolding_Flag may be modified if that option is selected
--| Disable_Underlining_Flag may be modified if that option is selected
--| Error_Logging_Flag may be modified if that option is selected
--| Page_Offset may be modified if that option is selected
--|
--|Options processed:
--| -da Disable all backspacing
--| -db Disable bolding (for drafts)
--| -du Disable underlining (for drafts)
--| -el Error logging to error.log
--| -po# Set initial page offset (default is 0)
--| -H or -h Display help message only
Current_Option
: OPTION_ID
:= UNKNOWN;
Option_Text
: OPTION_STRING
:= " ";
begin -- Process_Options
if not Is_File(Item) then
if Item'Length >= 3 then
Option_Text := Item(Item'First + 1 .. Item'First + 2);
elsif Item'Length = 2 then
Option_Text(1) := Item(Item'First + 1);
end if;
for I in Option'range loop
if Option_Text = Option(I).Name then
Current_Option := Option(I).Id;
end if;
end loop;
case Current_Option is
when DISABLE_ALL =>
Disable_Bolding_Flag := true;
Disable_Underlining_Flag := true;
when DISABLE_BOLDING =>
Disable_Bolding_Flag := true;
when DISABLE_UNDERLINING =>
Disable_Underlining_Flag := true;
when DISPLAY_HELP =>
Help_Message;
when ERROR_LOGGING =>
Error_Logging_Flag := true;
when SET_PAGE_OFFSET =>
begin
Page_Offset := NATURAL'Value(Item(Item'First+2 .. Item'Last));
exception
when others =>
Valid_Options := false;
Page_Offset := 0;
end;
when UNKNOWN =>
Valid_Options := false;
Error_Log.Write_Error(Error_Invalid_Option);
end case;
end if; -- not Is_File
end Process_Options;
-- ....................................
-- . .
-- . Open_Output_File . SPEC & BODY
-- . .
-- ....................................
function Open_Output_File
return BOOLEAN is
--| Purpose
--| Open_Output_File makes sure the target file does not exist,
--| prompts the user if it does, and opens it for output.
--| This function returns TRUE if the output file is successfully
--| opened.
--|
--| Exceptions (none)
--| Notes (none)
Cancel
: BOOLEAN
:= false;
Result
: Word_Processor.Operation_Status;
Answer
: STRING (1 .. 10);
Answer_Last
: NATURAL;
begin -- Open_Output_File
if Output_File.Already_Exists(CLP.Output_File_Name) then
Console.Put_Line(" Output File " & CLP.Output_File_Name &
" Exists");
Console.Put(" Erase it and proceed (Y/N)? ");
Console.Get_Line(Answer, Answer_Last);
if Answer_Last > 0 then
if (Answer(1) = 'y') or (Answer(1) = 'Y') then
if not Output_File.Delete(CLP.Output_File_Name) then
Error_Log.Write_Error(Error_Delete_File);
Cancel := true;
end if;
else
Error_Log.Write_Error(Error_User_Abort);
Cancel := true;
end if;
else
Error_Log.Write_Error(Error_User_Abor